<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>

<html>
<head>
	<script type="text/javascript" src="<c:url value="/resources/script/jquery/jconfirmaction.jquery.js"/>"></script>
	<script type="text/javascript">	
		$(document).ready(function() {
			$('.ask').jConfirmAction();
		});	
		
		function toggle(source) {
			checkboxes = document.getElementsByName('foo');
			for ( var i in checkboxes)
				checkboxes[i].checked = source.checked;
		}
		
		function ChangeState(obj) {
			var act = obj.disabled ? false : true;
			obj.disabled = act;
		}
	</script>
</head>
<body>
	<!-- cek unsaved item from importing excel file -->
	<c:choose>
		<c:when test="${empty unsavedItem}"></c:when>
		<c:otherwise>
			alert('
				<c:forEach var="unsaved" items="${unsavedItem}" varStatus="status">
					Item: ${unsaved} has not saved yet, please check
				</c:forEach>
			');
		</c:otherwise>
	</c:choose>
	
	<div>
	<form name="form" action="<c:url value="/item/history/deleteAll"/>" method="post">
		<table>
			<tr>
				<th align="left"><h2>List History</h2></th>
				<th>
					<a
					href="<c:url value="/item/history/restoreHistory"/>"
					class="bt_green"><span class="bt_green_lft"></span><strong>
					Deactivated History</strong><span class="bt_green_r"></span></a>
				</th>
			</tr>
			<tr>
				<td colspan="2">
					
						<table id="rounded-corner"
							summary="2007 Major IT Companies' Profit">
							<thead>
								<tr>
									<th scope="col" class="rounded-company"><input
										type="checkbox" onClick="toggle(this); ChangeState(box);" />
									</th>
									<th scope="col" class="rounded"><b>Date</b></th>
									<th scope="col" class="rounded"><b>Item</b></th>
									<th scope="col" class="rounded"><b>Location</b></th>
									<th scope="col" class="rounded"><b>User</b></th>
									<th scope="col" class="rounded"><b>Edit</b></th>
									<th scope="col" class="rounded-q4"><b>Delete</b></th>
								</tr>
							</thead>
							<tbody>
								<c:forEach var="history" items="${history}" varStatus="status">
									<tr>
										<td><input type="checkbox" name="foo" onClick="ChangeState(box);"
											value="${history.id}" /></td>
										<td>${history.date}</td>
										<td>${history.item.code}</td>
										<td>${history.location.position}</td>
										<td>${history.user.name}</td>
										<td><a class="view"
											href="<c:url value="/item/history/editHistory?id=${history.id}"/>"
											class="editItem"><img
												src="<c:url value="/resources/images/images/user_edit.png"/>"
												alt="" title="" border="0" /> </a></td>
										<td><a class="ask"
											href="<c:url value="/item/history/delete?id=${history.id}"/>"><img
												src="<c:url value="/resources/images/images/trash.png"/>"
												alt="" title="" border="0" /> </a></td>
									</tr>
								</c:forEach>
							</tbody>
							<tfoot>
								<tr>
									<td colspan="6" class="rounded-foot-left"><em>@Xsis
											Mitra Utama</em></td>
									<td class="rounded-foot-right">&nbsp;</td>
								</tr>
							</tfoot>
						</table>
					
				</td>
			</tr>
			<tr>
				<td colspan="2" align="right">
					<a onclick="document.form.submit()"
					href="<c:url value="#"/>"
					class="bt_green"><span class="bt_green_lft"></span><strong>
					 Delete </strong><span class="bt_green_r"></span> </a>
				</td>
			</tr>
		</table>
		</form>
	</div>
	<div>
		<p><font color="blue">Import data from Excel file:</font></p>
		<form action="upload" method="post" enctype="multipart/form-data"
			onSubmit="if(document.getElementById('fileinput').value == ''){alert('Choose file!'); return false;} ">
			<input size="70" type="file" name="spreadsheet" id="fileinput" /> 
			<input type="submit" value="Upload File" />
		</form>
	</div>
</body>
</html>